﻿#region NeoPatterns
// 
// NeoPatterns framework is released under LGPLv3 license.
// See http://www.opensource.org/licenses/lgpl-3.0.html for more details.
// 
// Please visit http://neopatterns.wikidot.com for more information about NeoPatterns
// 
// Copyright (c) Pascal Craponne 2008
// 
#endregion

using System.Collections.Generic;

namespace NeoPatterns.Utility
{
    public static class DictionaryUtility
    {
        /// <summary>
        /// Adds keys and values to a dictionary
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="dictionary"></param>
        /// <param name="key0"></param>
        /// <param name="value0"></param>
        /// <param name="value2"></param>
        /// <param name="keyValue3toN"></param>
        /// <param name="key1"></param>
        /// <param name="value1"></param>
        /// <param name="key2"></param>
        public static void Set<TKey, TValue>(this IDictionary<TKey, TValue> dictionary,
            TKey key0, TValue value0, TKey key1, TValue value1, TKey key2, TValue value2,
            params object[] keyValue3toN)
        {
            dictionary[key0] = value0;
            dictionary[key1] = value1;
            dictionary[key2] = value2;
            for (int keyValueIndex = 0; keyValueIndex < keyValue3toN.Length; keyValueIndex += 2)
                dictionary[(TKey)keyValue3toN[keyValueIndex]] = (TValue)keyValue3toN[keyValueIndex + 1];
        }

        /// <summary>
        /// Adds keys and values to a dictionary
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="dictionary"></param>
        /// <param name="key0"></param>
        /// <param name="value0"></param>
        public static void Set<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key0, TValue value0)
        {
            dictionary[key0] = value0;
        }

        /// <summary>
        /// Adds keys and values to a dictionary
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="dictionary"></param>
        /// <param name="key0"></param>
        /// <param name="value0"></param>
        /// <param name="key1"></param>
        /// <param name="value1"></param>
        public static void Set<TKey, TValue>(this IDictionary<TKey, TValue> dictionary,
            TKey key0, TValue value0, TKey key1, TValue value1)
        {
            dictionary[key0] = value0;
            dictionary[key1] = value1;
        }

        /// <summary>
        /// Adds keys and values to a dictionary
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="dictionary"></param>
        /// <param name="key0"></param>
        /// <param name="value0"></param>
        /// <param name="key1"></param>
        /// <param name="value1"></param>
        /// <param name="key2"></param>
        /// <param name="value2"></param>
        public static void Set<TKey, TValue>(this IDictionary<TKey, TValue> dictionary,
            TKey key0, TValue value0, TKey key1, TValue value1, TKey key2, TValue value2)
        {
            dictionary[key0] = value0;
            dictionary[key1] = value1;
            dictionary[key2] = value2;
        }

        /// <summary>
        /// Creates a new dictionary with given values
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="key0"></param>
        /// <param name="value0"></param>
        /// <returns></returns>
        public static IDictionary<TKey, TValue> New<TKey, TValue>(TKey key0, TValue value0)
        {
            var dictionary = new Dictionary<TKey, TValue>();
            dictionary[key0] = value0;
            return dictionary;
        }

        /// <summary>
        /// Creates a new dictionary with given values
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="key0"></param>
        /// <param name="value0"></param>
        /// <param name="key1"></param>
        /// <param name="value1"></param>
        /// <returns></returns>
        public static IDictionary<TKey, TValue> New<TKey, TValue>(TKey key0, TValue value0, TKey key1, TValue value1)
        {
            var dictionary = new Dictionary<TKey, TValue>();
            dictionary[key0] = value0;
            dictionary[key1] = value1;
            return dictionary;
        }

        /// <summary>
        /// Creates a new dictionary with given values
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="key0"></param>
        /// <param name="value0"></param>
        /// <param name="key1"></param>
        /// <param name="value1"></param>
        /// <param name="key2"></param>
        /// <param name="value2"></param>
        /// <returns></returns>
        public static IDictionary<TKey, TValue> New<TKey, TValue>(TKey key0, TValue value0, TKey key1, TValue value1, TKey key2, TValue value2)
        {
            var dictionary = new Dictionary<TKey, TValue>();
            dictionary[key0] = value0;
            dictionary[key1] = value1;
            dictionary[key2] = value2;
            return dictionary;
        }

        /// <summary>
        /// Creates a new dictionary with given values
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="key0"></param>
        /// <param name="value0"></param>
        /// <param name="key1"></param>
        /// <param name="value1"></param>
        /// <param name="key2"></param>
        /// <param name="value2"></param>
        /// <param name="keyValue3toN"></param>
        /// <returns></returns>
        public static IDictionary<TKey, TValue> New<TKey, TValue>(TKey key0, TValue value0, TKey key1, TValue value1, TKey key2, TValue value2,
            params object[] keyValue3toN)
        {
            var dictionary = new Dictionary<TKey, TValue>();
            dictionary[key0] = value0;
            dictionary[key1] = value1;
            dictionary[key2] = value2;
            for (int keyValueIndex = 0; keyValueIndex < keyValue3toN.Length; keyValueIndex += 2)
                dictionary[(TKey)keyValue3toN[keyValueIndex]] = (TValue)keyValue3toN[keyValueIndex + 1];
            return dictionary;
        }
    }
}
